package com.xiaoyu.lingdian.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.xiaoyu.lingdian.service.CorePointsProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xiaoyu.lingdian.core.mybatis.dao.MyBatisDAO;
import com.xiaoyu.lingdian.core.mybatis.page.Page;
import com.xiaoyu.lingdian.core.mybatis.page.PageRequest;
import com.xiaoyu.lingdian.entity.CorePointsProduct;

@Service("corePointsProductService")
public class CorePointsProductServiceImpl implements CorePointsProductService {

	@Autowired
	private MyBatisDAO myBatisDAO;

	@Override
	public boolean insertCorePointsProduct(CorePointsProduct corePointsProduct) {
		myBatisDAO.insert(corePointsProduct);
		return true;
	}

	@Override
	public boolean updateCorePointsProduct(CorePointsProduct corePointsProduct) {
		myBatisDAO.update(corePointsProduct);
		return true;
	}

	@Override
	public boolean deleteCorePointsProduct(CorePointsProduct corePointsProduct) {
		myBatisDAO.delete(corePointsProduct);
		return true;
	}

	@Override
	public CorePointsProduct getCorePointsProduct(CorePointsProduct corePointsProduct) {
		return (CorePointsProduct) myBatisDAO.findForObject(corePointsProduct);
	}

	private static final String FIND_CORE_POINTSPRODUCT_BY_CND = "findCorePointsProductByCnd";
	private static final String DELETE_CORE_POINTSPRODUCT_BY_CND = "deleteCorePointsProductByCnd";
	private static final String UPDATE_CORE_POINTSPRODUCT_DESC = "updateCorePointsProductDesc";
	
	@SuppressWarnings("unchecked")
	@Override
	public Page<CorePointsProduct> findCorePointsProductByCnd(
			String crpopTitle, String crpopArea, int pageNum, int pageSize) {
		Map<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("crpopTitle", crpopTitle);
		hashMap.put("crpopArea", crpopArea);
		return myBatisDAO.findForPage(FIND_CORE_POINTSPRODUCT_BY_CND, new PageRequest(pageNum, pageSize, hashMap));
	}

	@Override
	public boolean deleteCorePointsProductByCnd(List<String> list) {
		Map<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("list", list);
		myBatisDAO.delete(DELETE_CORE_POINTSPRODUCT_BY_CND, hashMap);
		return true;
	}

	@Override
	public boolean updateCorePointsProductDesc(CorePointsProduct corePointsProduct) {
		myBatisDAO.update(UPDATE_CORE_POINTSPRODUCT_DESC, corePointsProduct);
		return true;
	}

}